/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xmppbot.parse;

import java.sql.SQLException;
import java.util.ArrayList;
import org.jivesoftware.smack.XMPPException;

/**
 *
 * @author lian
 */
public class utils {
    @SuppressWarnings("unchecked")
    public static String parseSymbols (String str) {
        ArrayList symbols = new ArrayList();
        symbols.add("'");
        //symbols.add("%");
        //symbols.add("_");
        symbols.add("\\");
        symbols.add("\"");
        for (int i = 0; i < symbols.size();i++) {
            if (str.contains((CharSequence) symbols.get(i))) {
                String strs[] = str.split((String) symbols.get(i));
                str = strs[0];
                for (int f = 1; f < strs.length; f++) {
                    str = str + "\\" + ((String) symbols.get(i)) + strs[f];
                }
            }
        }
        return str;
    }
    
    public static packet creatPacket (options opts) throws SQLException, XMPPException {
        packet pack;
        if (opts.getSessionAttached()) {
            pack = new SessionPacket(opts);
        } else {
            pack = new NormPacket(opts);
        }
        return pack;
    }
}
